﻿using System;
using System.Windows.Input;

namespace MenusHunter.WinRT.Core.MVVM
{
    /// <summary>
    /// This class is ViewModel Parents
    /// Extend validatable class for validation
    /// </summary>
    public class ViewModelBase : BindableBase
    {
        #region Fields

        private bool _isBusy = false;

        private bool _idle = true;
        private INavigateServcie navigateServcie;
        private ICommand _goBackCommand;
        private ICommand _goForwardCommand;

        #endregion

        #region Creation

        public ViewModelBase()
        {
        }

        public ViewModelBase(INavigateServcie navigateService)
        {
        }

        #endregion

        #region Navigations
          /// <summary>
          /// Go back page command
          /// </summary>
        public ICommand GoBackCommand
        {
            get
            {
                if (_goBackCommand == null)
                {
                    _goBackCommand = new ReplayCommand(param => GoBack(), can => navigateServcie.CanGoBack);
                }
                return _goBackCommand;
            }
        }

        /// <summary>
        ///  GoBack page 
        /// </summary>
        public void GoBack()
        {
            navigateServcie.GoBack();
        }

        /// <summary>
        ///Go forward page command
        /// </summary>
        public ICommand GoForwardCommand
        {
            get
            {
                if (_goForwardCommand == null)
                    _goForwardCommand = new ReplayCommand(param => GoForward(), param => navigateServcie.CanGoForward);
                return _goForwardCommand;
            }
        }

        /// <summary>
        ///   Go forward page
        /// </summary>
        public void GoForward()
        {
            navigateServcie.GoForward();
        }
         /// <summary>
         /// Navigate to page
         /// </summary>
         /// <param name="type">class type of page</param>
         /// <param name="parameter">parameter for page navigate to</param>
        public void Navigate(Type type, object parameter = null)
        {
            navigateServcie.Navigate(type, parameter);
        }

        #endregion

        #region Properties

        /// <summary>
        /// view is busy or in a proccess
        /// </summary>
        public bool IsBusy
        {
            get { return _isBusy; }
            set
            {
                SetProperty(ref _isBusy, value);
                Idle = !_isBusy;
            }
        }

        /// <summary>
        /// State idle of view
        /// </summary>
        public bool Idle
        {
            get { return _idle; }
            set { SetProperty(ref _idle, value); }
        }

        #endregion
    }
}